home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 March / maximum-cd-2000-03.iso / Quake3 Game Source / Q3AGameSource.exe / Main / ui_sound.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-18  |  10.1 KB  |  297 lines

  1. // Copyright (C) 1999-2000 Id Software, Inc.
  2. //
  3. /*
  4. =======================================================================
  5.  
  6. SOUND OPTIONS MENU
  7.  
  8. =======================================================================
  9. */
  10.  
  11. #include "ui_local.h"
  12.  
  13.  
  14. #define ART_FRAMEL            "menu/art/frame2_l"
  15. #define ART_FRAMER            "menu/art/frame1_r"
  16. #define ART_BACK0            "menu/art/back_0"
  17. #define ART_BACK1            "menu/art/back_1"
  18.  
  19. #define ID_GRAPHICS            10
  20. #define ID_DISPLAY            11
  21. #define ID_SOUND            12
  22. #define ID_NETWORK            13
  23. #define ID_EFFECTSVOLUME    14
  24. #define ID_MUSICVOLUME        15
  25. #define ID_QUALITY            16
  26. #define ID_A3D                17
  27. #define ID_BACK                18
  28.  
  29.  
  30. static const char *quality_items[] = {
  31.     "Low", "High", 0
  32. };
  33.  
  34. typedef struct {
  35.     menuframework_s        menu;
  36.  
  37.     menutext_s            banner;
  38.     menubitmap_s        framel;
  39.     menubitmap_s        framer;
  40.  
  41.     menutext_s            graphics;
  42.     menutext_s            display;
  43.     menutext_s            sound;
  44.     menutext_s            network;
  45.  
  46.     menuslider_s        sfxvolume;
  47.     menuslider_s        musicvolume;
  48.     menulist_s            quality;
  49.     menuradiobutton_s    a3d;
  50.  
  51.     menubitmap_s        back;
  52. } soundOptionsInfo_t;
  53.  
  54. static soundOptionsInfo_t    soundOptionsInfo;
  55.  
  56.  
  57. /*
  58. =================
  59. UI_SoundOptionsMenu_Event
  60. =================
  61. */
  62. static void UI_SoundOptionsMenu_Event( void* ptr, int event ) {
  63.     if( event != QM_ACTIVATED ) {
  64.         return;
  65.     }
  66.  
  67.     switch( ((menucommon_s*)ptr)->id ) {
  68.     case ID_GRAPHICS:
  69.         UI_PopMenu();
  70.         UI_GraphicsOptionsMenu();
  71.         break;
  72.  
  73.     case ID_DISPLAY:
  74.         UI_PopMenu();
  75.         UI_DisplayOptionsMenu();
  76.         break;
  77.  
  78.     case ID_SOUND:
  79.         break;
  80.  
  81.     case ID_NETWORK:
  82.         UI_PopMenu();
  83.         UI_NetworkOptionsMenu();
  84.         break;
  85.  
  86.     case ID_EFFECTSVOLUME:
  87.         trap_Cvar_SetValue( "s_volume", soundOptionsInfo.sfxvolume.curvalue / 10 );
  88.         break;
  89.  
  90.     case ID_MUSICVOLUME:
  91.         trap_Cvar_SetValue( "s_musicvolume", soundOptionsInfo.musicvolume.curvalue / 10 );
  92.         break;
  93.  
  94.     case ID_QUALITY:
  95.         if( soundOptionsInfo.quality.curvalue ) {
  96.             trap_Cvar_SetValue( "s_khz", 22 );
  97.             trap_Cvar_SetValue( "s_compression", 0 );
  98.         }
  99.         else {
  100.             trap_Cvar_SetValue( "s_khz", 11 );
  101.             trap_Cvar_SetValue( "s_compression", 1 );
  102.         }
  103.         UI_ForceMenuOff();
  104.         trap_Cmd_ExecuteText( EXEC_APPEND, "snd_restart\n" );
  105.         break;
  106.  
  107.     case ID_A3D:
  108.         if( soundOptionsInfo.a3d.curvalue ) {
  109.             trap_Cmd_ExecuteText( EXEC_NOW, "s_enable_a3d\n" );
  110.         }
  111.         else {
  112.             trap_Cmd_ExecuteText( EXEC_NOW, "s_disable_a3d\n" );
  113.         }
  114.         soundOptionsInfo.a3d.curvalue = (int)trap_Cvar_VariableValue( "s_usingA3D" );
  115.         break;
  116.  
  117.     case ID_BACK:
  118.         UI_PopMenu();
  119.         break;
  120.     }
  121. }
  122.  
  123.  
  124. /*
  125. ===============
  126. UI_SoundOptionsMenu_Init
  127. ===============
  128. */
  129. static void UI_SoundOptionsMenu_Init( void ) {
  130.     int                y;
  131.  
  132.     memset( &soundOptionsInfo, 0, sizeof(soundOptionsInfo) );
  133.  
  134.     UI_SoundOptionsMenu_Cache();
  135.     soundOptionsInfo.menu.wrapAround = qtrue;
  136.     soundOptionsInfo.menu.fullscreen = qtrue;
  137.  
  138.     soundOptionsInfo.banner.generic.type        = MTYPE_BTEXT;
  139.     soundOptionsInfo.banner.generic.flags        = QMF_CENTER_JUSTIFY;
  140.     soundOptionsInfo.banner.generic.x            = 320;
  141.     soundOptionsInfo.banner.generic.y            = 16;
  142.     soundOptionsInfo.banner.string                = "SYSTEM SETUP";
  143.     soundOptionsInfo.banner.color                = color_white;
  144.     soundOptionsInfo.banner.style                = UI_CENTER;
  145.  
  146.     soundOptionsInfo.framel.generic.type        = MTYPE_BITMAP;
  147.     soundOptionsInfo.framel.generic.name        = ART_FRAMEL;
  148.     soundOptionsInfo.framel.generic.flags        = QMF_INACTIVE;
  149.     soundOptionsInfo.framel.generic.x            = 0;  
  150.     soundOptionsInfo.framel.generic.y            = 78;
  151.     soundOptionsInfo.framel.width                = 256;
  152.     soundOptionsInfo.framel.height                = 329;
  153.  
  154.     soundOptionsInfo.framer.generic.type        = MTYPE_BITMAP;
  155.     soundOptionsInfo.framer.generic.name        = ART_FRAMER;
  156.     soundOptionsInfo.framer.generic.flags        = QMF_INACTIVE;
  157.     soundOptionsInfo.framer.generic.x            = 376;
  158.     soundOptionsInfo.framer.generic.y            = 76;
  159.     soundOptionsInfo.framer.width                = 256;
  160.     soundOptionsInfo.framer.height                = 334;
  161.  
  162.     soundOptionsInfo.graphics.generic.type        = MTYPE_PTEXT;
  163.     soundOptionsInfo.graphics.generic.flags        = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
  164.     soundOptionsInfo.graphics.generic.id        = ID_GRAPHICS;
  165.     soundOptionsInfo.graphics.generic.callback    = UI_SoundOptionsMenu_Event;
  166.     soundOptionsInfo.graphics.generic.x            = 216;
  167.     soundOptionsInfo.graphics.generic.y            = 240 - 2 * PROP_HEIGHT;
  168.     soundOptionsInfo.graphics.string            = "GRAPHICS";
  169.     soundOptionsInfo.graphics.style                = UI_RIGHT;
  170.     soundOptionsInfo.graphics.color                = color_red;
  171.  
  172.     soundOptionsInfo.display.generic.type        = MTYPE_PTEXT;
  173.     soundOptionsInfo.display.generic.flags        = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
  174.     soundOptionsInfo.display.generic.id            = ID_DISPLAY;
  175.     soundOptionsInfo.display.generic.callback    = UI_SoundOptionsMenu_Event;
  176.     soundOptionsInfo.display.generic.x            = 216;
  177.     soundOptionsInfo.display.generic.y            = 240 - PROP_HEIGHT;
  178.     soundOptionsInfo.display.string                = "DISPLAY";
  179.     soundOptionsInfo.display.style                = UI_RIGHT;
  180.     soundOptionsInfo.display.color                = color_red;
  181.  
  182.     soundOptionsInfo.sound.generic.type            = MTYPE_PTEXT;
  183.     soundOptionsInfo.sound.generic.flags        = QMF_RIGHT_JUSTIFY;
  184.     soundOptionsInfo.sound.generic.id            = ID_SOUND;
  185.     soundOptionsInfo.sound.generic.callback        = UI_SoundOptionsMenu_Event;
  186.     soundOptionsInfo.sound.generic.x            = 216;
  187.     soundOptionsInfo.sound.generic.y            = 240;
  188.     soundOptionsInfo.sound.string                = "SOUND";
  189.     soundOptionsInfo.sound.style                = UI_RIGHT;
  190.     soundOptionsInfo.sound.color                = color_red;
  191.  
  192.     soundOptionsInfo.network.generic.type        = MTYPE_PTEXT;
  193.     soundOptionsInfo.network.generic.flags        = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
  194.     soundOptionsInfo.network.generic.id            = ID_NETWORK;
  195.     soundOptionsInfo.network.generic.callback    = UI_SoundOptionsMenu_Event;
  196.     soundOptionsInfo.network.generic.x            = 216;
  197.     soundOptionsInfo.network.generic.y            = 240 + PROP_HEIGHT;
  198.     soundOptionsInfo.network.string                = "NETWORK";
  199.     soundOptionsInfo.network.style                = UI_RIGHT;
  200.     soundOptionsInfo.network.color                = color_red;
  201.  
  202.     y = 240 - 1.5 * (BIGCHAR_HEIGHT + 2);
  203.     soundOptionsInfo.sfxvolume.generic.type        = MTYPE_SLIDER;
  204.     soundOptionsInfo.sfxvolume.generic.name        = "Effects Volume:";
  205.     soundOptionsInfo.sfxvolume.generic.flags    = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  206.     soundOptionsInfo.sfxvolume.generic.callback    = UI_SoundOptionsMenu_Event;
  207.     soundOptionsInfo.sfxvolume.generic.id        = ID_EFFECTSVOLUME;
  208.     soundOptionsInfo.sfxvolume.generic.x        = 400;
  209.     soundOptionsInfo.sfxvolume.generic.y        = y;
  210.     soundOptionsInfo.sfxvolume.minvalue            = 0;
  211.     soundOptionsInfo.sfxvolume.maxvalue            = 10;
  212.  
  213.     y += BIGCHAR_HEIGHT+2;
  214.     soundOptionsInfo.musicvolume.generic.type        = MTYPE_SLIDER;
  215.     soundOptionsInfo.musicvolume.generic.name        = "Music Volume:";
  216.     soundOptionsInfo.musicvolume.generic.flags        = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  217.     soundOptionsInfo.musicvolume.generic.callback    = UI_SoundOptionsMenu_Event;
  218.     soundOptionsInfo.musicvolume.generic.id            = ID_MUSICVOLUME;
  219.     soundOptionsInfo.musicvolume.generic.x            = 400;
  220.     soundOptionsInfo.musicvolume.generic.y            = y;
  221.     soundOptionsInfo.musicvolume.minvalue            = 0;
  222.     soundOptionsInfo.musicvolume.maxvalue            = 10;
  223.  
  224.     y += BIGCHAR_HEIGHT+2;
  225.     soundOptionsInfo.quality.generic.type        = MTYPE_SPINCONTROL;
  226.     soundOptionsInfo.quality.generic.name        = "Sound Quality:";
  227.     soundOptionsInfo.quality.generic.flags        = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  228.     soundOptionsInfo.quality.generic.callback    = UI_SoundOptionsMenu_Event;
  229.     soundOptionsInfo.quality.generic.id            = ID_QUALITY;
  230.     soundOptionsInfo.quality.generic.x            = 400;
  231.     soundOptionsInfo.quality.generic.y            = y;
  232.     soundOptionsInfo.quality.itemnames            = quality_items;
  233.  
  234.     y += BIGCHAR_HEIGHT+2;
  235.     soundOptionsInfo.a3d.generic.type            = MTYPE_RADIOBUTTON;
  236.     soundOptionsInfo.a3d.generic.name            = "A3D:";
  237.     soundOptionsInfo.a3d.generic.flags            = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  238.     soundOptionsInfo.a3d.generic.callback        = UI_SoundOptionsMenu_Event;
  239.     soundOptionsInfo.a3d.generic.id                = ID_A3D;
  240.     soundOptionsInfo.a3d.generic.x                = 400;
  241.     soundOptionsInfo.a3d.generic.y                = y;
  242.  
  243.     soundOptionsInfo.back.generic.type            = MTYPE_BITMAP;
  244.     soundOptionsInfo.back.generic.name            = ART_BACK0;
  245.     soundOptionsInfo.back.generic.flags            = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  246.     soundOptionsInfo.back.generic.callback        = UI_SoundOptionsMenu_Event;
  247.     soundOptionsInfo.back.generic.id            = ID_BACK;
  248.     soundOptionsInfo.back.generic.x                = 0;
  249.     soundOptionsInfo.back.generic.y                = 480-64;
  250.     soundOptionsInfo.back.width                    = 128;
  251.     soundOptionsInfo.back.height                = 64;
  252.     soundOptionsInfo.back.focuspic                = ART_BACK1;
  253.  
  254.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.banner );
  255.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.framel );
  256.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.framer );
  257.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.graphics );
  258.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.display );
  259.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.sound );
  260.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.network );
  261.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.sfxvolume );
  262.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.musicvolume );
  263.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.quality );
  264.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.a3d );
  265.     Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.back );
  266.  
  267.     soundOptionsInfo.sfxvolume.curvalue = trap_Cvar_VariableValue( "s_volume" ) * 10;
  268.     soundOptionsInfo.musicvolume.curvalue = trap_Cvar_VariableValue( "s_musicvolume" ) * 10;
  269.     soundOptionsInfo.quality.curvalue = !trap_Cvar_VariableValue( "s_compression" );
  270.     soundOptionsInfo.a3d.curvalue = (int)trap_Cvar_VariableValue( "s_usingA3D" );
  271. }
  272.  
  273.  
  274. /*
  275. ===============
  276. UI_SoundOptionsMenu_Cache
  277. ===============
  278. */
  279. void UI_SoundOptionsMenu_Cache( void ) {
  280.     trap_R_RegisterShaderNoMip( ART_FRAMEL );
  281.     trap_R_RegisterShaderNoMip( ART_FRAMER );
  282.     trap_R_RegisterShaderNoMip( ART_BACK0 );
  283.     trap_R_RegisterShaderNoMip( ART_BACK1 );
  284. }
  285.  
  286.  
  287. /*
  288. ===============
  289. UI_SoundOptionsMenu
  290. ===============
  291. */
  292. void UI_SoundOptionsMenu( void ) {
  293.     UI_SoundOptionsMenu_Init();
  294.     UI_PushMenu( &soundOptionsInfo.menu );
  295.     Menu_SetCursorToItem( &soundOptionsInfo.menu, &soundOptionsInfo.sound );
  296. }
  297.